<template>
  <!-- 购物加减按钮组件 -->
  <div class="cartcontrot">
    <transition name="move">
      <div class="cart-decrease" v-show="food.count>0" @click.stop="decreaseCart($event)">
        <span class="inner iconfont icon-wuuiconsuoxiao"></span>
      </div>
    </transition>
    <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
    <div class="cart-add iconfont icon-jia" @click.stop="addcart($event)"></div>
  </div>
</template>

<script>
import Vue from "vue";
export default {
  props: {
    food: {
      type: Object
    }
  },
  created() {},
  methods: {
    addcart(event) {
      if (!event._constructed) {
        //解决在pc端点击会点击两次
        return;
      }
      if (!this.food.count) {
        Vue.set(this.food, "count", 1);
      } else {
        this.food.count++;
      }
    },
    decreaseCart(event) {
      if (!event._constructed) {
        //解决在pc端点击会点击两次
        return;
      }
      if (this.food.count) {
        this.food.count--;
      }
    }
  }
};
</script>

<style lang = "scss">
.cartcontrot {
  font-size: 0px;
  .cart-decrease {
    display: inline-block;
    padding: 6px;
    line-height: 24px;
    font-size: 24px;
    color: #00a0dc;
  }
  .inner {
    display: inline-block;
    line-height: 24px;
    font-size: 24px;
    color: rgb(0, 160, 220);
  }

  /* transition过渡动画 */
  .move-enter,
  .move-leave-to {
    opacity: 0;
    transform: translate3d(24px, 0, 0) rotate(0);
  }

  .move-enter-to,
  .move-leave {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(-180deg);
  }

  .move-enter-active,
  .move-leave-active {
    transition: all 0.4s linear;
  }

  .cart-count {
    display: inline-block;
    vertical-align: top;
    padding: 6px;
    width: 12px;
    font-size: 10px;
    color: rgb(147, 153, 159);
    line-height: 24px;
    text-align: center;
  }
  .cart-add {
    display: inline-block;
    padding: 6px;
    line-height: 24px;
    font-size: 24px;
    color: rgb(0, 160, 220);
  }
}
</style>
